package br.com.absolutech.study.chapter9.test16;

public class Test {

	public static void main(String[] args) {

		final Foo f = new Foo();

		Thread t = new Thread(new Runnable() { //o.0 (pag 371)

					public void run() {
						f.doStuff();
					}
				});
		Thread g = new Thread() {

			public void run() {
				f.doStuff();
			}
		};
		t.start();
		g.start();

	}
}

class Foo {
	int x = 5;

	public void doStuff() {
		if (x < 10) {
			//nada a fazer
			try {
				wait();
			} catch (InterruptedException ex) {
			}
		} else {
			System.out.println("x is " + x++);
			if (x >= 10) {
				notify();
			}
		}
	}
}
